package org.jage.student.missevo.solution.migration;

import java.util.Collection;

import org.jage.agent.IAgent;
import org.jage.agent.IAgentEnvironment;
import org.jage.platform.component.annotation.Inject;
import org.jage.property.ClassPropertyContainer;
import org.jage.property.IPropertiesSet;
import org.jage.property.PropertyField;
import org.jage.query.AgentEnvironmentQuery;
import org.jage.random.IDoubleRandomGenerator;

public class RandomShouldMigrate extends ClassPropertyContainer implements IShouldMigrate {
	
	private AgentEnvironmentQuery<IAgent, IAgent> emptyQuery;

	
    @PropertyField(propertyName = "chanceToMigrate")
    @Inject
    private double chanceToMigrate;

    @PropertyField(propertyName = "rand")
    @Inject
    private IDoubleRandomGenerator rand;

    @Override
    public boolean decide(Collection<?> queryResult, IAgent agent) {
        if (rand.nextDouble() < chanceToMigrate) {
            return true;
        }
        return false;
    }
    
    public AgentEnvironmentQuery<IAgent, IAgent> query() {
		if (emptyQuery == null) {
			emptyQuery = new AgentEnvironmentQuery<IAgent, IAgent>();
		}
		return emptyQuery;
	}


}
